package caesar;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

public class CaesarDecode extends FilterInputStream {
	int key;	
	public CaesarDecode(InputStream in, int k) {
		super(in);
		key =k;
	}

	
	public int read() throws IOException{
			return decode((char) super.read());		
	}
	
//Character.isLetter(help) && 
	
	private char decode(char clear){
		char help = clear;
		if((help >= 'A' && help <= 'Z') || (help >= 'a' && help <= 'z'))
			if (Character.isUpperCase(help))
				if ((help + key) > 90)
					help = (char) (help + key - 26);
				else
					help += key;
			else
				if ((help + key) > 122)
					help = (char) (help + key - 26);
				else
					help += key;
		return help;
	}
}
